package com.twu.biblioteca;

import java.util.HashMap;
import java.util.Map;

public class Movies {

    private HashMap<String,MoviesDetails> movies = new HashMap<String,MoviesDetails>();

    public Movies()
    {
        movies.put("Sholay",new MoviesDetails("Sholay","1975","Ramesh Sippy","*****"));
        movies.put("Toy Story",new MoviesDetails("Toy Story","1995","John Lasseter","****"));
        movies.put("Ratatouille",new MoviesDetails("Ratatouille","2007","Brad Bird","*****"));
        movies.put("WALL-E",new MoviesDetails("WALL-E","2008","Andrew Stanton","***"));
        movies.put("Leap year",new MoviesDetails("Leap year","2010","Anand Tucker","***"));
        movies.put("Up",new MoviesDetails("Up","2009","Pete Docter","**"));
        movies.put("Spell Bound",new MoviesDetails("Spell Bound","1945","Alfred Hitchcock","*****"));
        movies.put("The Help",new MoviesDetails("The Help", "2011","Tate Taylor","***"));
        movies.put("The Godfather",new MoviesDetails("The Godfather","1972","Francis Ford Coppola","*****"));
        movies.put("Yeh Jawaani Hai Diwaani",new MoviesDetails("Yeh Jawaani Hai Diwaani","2013","Ayan Mukherjee","N/A"));
    }

    public HashMap<String, MoviesDetails> getMovies() {
        return movies;
    }

    public void addMovies(String name, String year, String director, String rating)
    {
        movies.put(name, new MoviesDetails(name,year,director,rating));
    }

    public void displayMoviesList()
    {
        Map<String, MoviesDetails> map = movies;
        System.out.println("The list of movies is:\n");
        for (Map.Entry<String, MoviesDetails> entry : map.entrySet()) {
            System.out.println(entry.getKey());
        }
    }

    public void displayMoviesDetails(String name)
    {
        Map<String, MoviesDetails> map = movies;
        System.out.println("The movie details are:\n");
        System.out.format("%-25s%-25s%-25s%s", "Movie", "Year", "Director", "Rating\n");
        for (Map.Entry<String, MoviesDetails> entry : map.entrySet()) {
            if(entry.getKey().equalsIgnoreCase(name))
            {
                MoviesDetails details = entry.getValue();
                System.out.format("%-25s%-25s%-25s%s", details.getName(), details.getYear(), details.getDirector(), details.getRating()+"\n");
            }
        }
    }

}
